package pl.cvplus.dao;

import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;
import pl.cvplus.entity.CpUser;

import java.util.Collection;

/**
 * Created by IntelliJ IDEA.
 * User: Piotrek
 * Date: 02.03.12
 * Time: 23:34
 * To change this template use File | Settings | File Templates.
 */
public class UserDaoImpl implements UserDao{

    private SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    @Transactional
    public String getName() {
        this.sessionFactory.getCurrentSession().beginTransaction().begin();
        String login =  getUserByLogin("first").getCpPasswordByPasswordFk().getUserPassword();
        return login;

    }

    public CpUser getUserByLogin(String login){
        return (CpUser) this.sessionFactory.getCurrentSession()
                .createQuery("from CpUser c where c.login like ? ")
                .setParameter(0,login)
                .setMaxResults(1)
                .uniqueResult();
    }



}
